﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace SMP.Resource
{
    using SMP.Domain;
    public class Mathang_Res : BaseDB
    {
        public DataTable GetAll_Mathang()
        {
            return ExecuteQuery("EXEC GetAll_Mathang ");
        }

        public DataTable GetAll_Mathang_Xuatkho()
        {
            return ExecuteQuery("EXEC GetAll_Mathang_Xuatkho ");
        }

        public DataTable Get_Mathang_Check_Used_By_Id_Mathang(long id_mathang)
        {
            string sql = @"EXEC Get_Mathang_Check_Used_By_Id_Mathang {0}";
            sql = string.Format(sql, id_mathang);
            return ExecuteQuery(sql);
        }

        public bool Delete_Mathang(long id_mathang)
        {
            string sql = string.Format(@"DELETE FROM tb_mathang WHERE id_mathang = {0}", id_mathang);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert_Mathang(Mathang mathang)
        {
            string sql = string.Format(@"INSERT INTO tb_mathang(id_nhom_mathang,id_donvi_tinh,ten_mathang,thongtin_mathang) VALUES ({0}, {1}, N'{2}', N'{3}')", 
                                                            mathang.Id_Nhom_Mathang, mathang.Id_Donvi_Tinh, mathang.Ten_Mathang, mathang.Thongtin_Mathang);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update_Mathang(Mathang mathang)
        {
            string sql = string.Format(@"UPDATE tb_mathang SET id_nhom_mathang = {0}, id_donvi_tinh = {1}, ten_mathang = N'{2}', thongtin_mathang = N'{3}')", 
                                                            mathang.Id_Nhom_Mathang, mathang.Id_Donvi_Tinh, mathang.Ten_Mathang, mathang.Thongtin_Mathang);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }



    }
}
